package com.plian.system.service.pm.property.helper;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.plian.Tools.CollectionUtil;
import com.plian.Tools.StringUtil;
import com.plian.Tools.UuidUtil;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.cache.PropertyCache;
import com.plian.system.constant.sys.FormStatusConstant;
import com.plian.system.dao.sys.file.FileDao;
import com.plian.system.entity.pm.property.*;
import com.plian.system.entity.sys.Org;
import com.plian.system.mapper.pm.property.PropertyChangeMapper;
import com.plian.system.service.pm.property.*;
import com.plian.system.service.sys.orgzation.IOrgService;
import com.plian.system.wrapper.pm.property.PropertyBasicsWrapper;
import com.plian.system.wrapper.pm.property.PropertyChangeWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
@AllArgsConstructor
public class PropertyChangeHelper {

    private IContributorChangeService contributorChangeService;

    private IShareholdingChangeService shareholdingChangeService;

    private IPartnerOutboundChangeService partnerOutboundChangeService;

    private IPartnerSituationChangeService partnerSituationChangeService;

    private IPropertyBasicsService propertyBasicsService;

    private IContributorBasicsService contributorBasicsService;

    private IShareholdingBasicsService shareholdingBasicsService;

    private IPartnerOutboundBasicsService partnerOutboundBasicsService;

    private IPartnerSituationBasicsService partnerSituationBasicsService;

    private IPropertyRecordService propertyRecordService;

    private IContributorRecordService contributorRecordService;

    private IShareholdingRecordService shareholdingRecordService;

    private IPartnerOutboundRecordService partnerOutboundRecordService;

    private IPartnerSituationRecordService partnerSituationRecordService;

    private PropertyChangeWrapper propertyChangeWrapper;

    private IOrgService orgService;

    private PropertyBasicsWrapper propertyBasicsWrapper;

    private FileDao fileDao;

    private PropertyChangeMapper propertyChangeMapper;

    /**
     * 产权变更时 对其他表进行对操作
     * @param id
     */
    @Transactional(rollbackFor = RuntimeException.class)
    public void changeWith(String id) {
        Date now = new Date();
        PropertyChange propertyChange = propertyChangeMapper.selectById(id);
        PropertyRecord propertyRecord = propertyRecordService.getById(propertyChange.getProId());
        PropertyBasics oldBasics = propertyBasicsService.getById(propertyRecord.getInitialId());

        PropertyBasics updateBasics = propertyChangeWrapper.changeToBasics(propertyChange);
        updateBasics.setId(oldBasics.getId());
        updateBasics.setCreateTime(oldBasics.getCreateTime());
        updateBasics.setUpdateTime(now);
        updateBasics.setCreateUser(oldBasics.getCreateUser());
        updateBasics.setUpdateUser(oldBasics.getUpdateUser());
        updateBasics.setFillOrgId(oldBasics.getFillOrgId());
        updateBasics.setStatus(oldBasics.getStatus());

        propertyBasicsService.updateById(updateBasics);
        PropertyCache.update(updateBasics.getId());
        String oldParentId = oldBasics.getParentId();
        if (!oldParentId.equals(updateBasics.getParentId())){
            propertyBasicsService.changeNewPropertyCode(propertyRecord.getInitialId(), updateBasics.getParentId());
        }
        propertyBasicsService.changeChildPrivateMix(propertyRecord.getInitialId(),
                propertyBasicsService.checkActualCapital5(updateBasics.getActualCapital5()) ? 1 : 0);

        PropertyRecord newRecord = propertyBasicsWrapper.basicsToRecord(updateBasics);
        newRecord.setCreateTime(now);
        newRecord.setUpdateTime(now);
        newRecord.setChangeId(propertyChange.getId());
        newRecord.setInitialId(propertyRecord.getInitialId());
        propertyRecordService.save(newRecord);
        copyFile(propertyChange.getId(), newRecord.getId());

//        //保存企业章程
//        saveAssociation(propertyChange, newRecord.getId());

        //出资人情况
        List<ContributorChange> contributorChanges = contributorChangeService.list(Wrappers.<ContributorChange>lambdaQuery()
                .eq(ContributorChange::getProChagId, propertyChange.getId()));
        contributorBasicsService.removeByPropertyId(Collections.singletonList(updateBasics.getId()));
        if (CollectionUtil.isNotEmpty(contributorChanges)){
            List<ContributorBasics> contributorBasicsList = propertyChangeWrapper.contributorChangeToBasics(contributorChanges);
            List<ContributorRecord> contributorRecordList = propertyChangeWrapper.contributorChangeToRecord(contributorChanges);
            for (ContributorBasics contributorBasics : contributorBasicsList){
                contributorBasics.setId(null);
                contributorBasics.setPropertyId(updateBasics.getId());
            }
            for (ContributorRecord contributorRecord : contributorRecordList){
                contributorRecord.setId(null);
                contributorRecord.setPropertyId(newRecord.getId());
            }
            contributorBasicsService.saveBatch(contributorBasicsList);
            contributorRecordService.saveBatch(contributorRecordList);
        }

        if ("1".equals(propertyChange.getNature())){
            //境外企业
            List<ShareholdingChange> shareholdingChanges = shareholdingChangeService.list(Wrappers.<ShareholdingChange>lambdaQuery()
                    .eq(ShareholdingChange::getPropertyId, propertyChange.getId()));
            shareholdingBasicsService.removeByPropertyId(Collections.singletonList(updateBasics.getId()));
            if (CollectionUtil.isNotEmpty(shareholdingChanges)){
                List<ShareholdingBasics> shareholdingBasicsList = propertyChangeWrapper.shareholdingChangeToBasics(shareholdingChanges);
                List<ShareholdingRecord> shareholdingRecordList = propertyChangeWrapper.shareholdingChangeToRecord(shareholdingChanges);
                for (ShareholdingBasics shareholdingBasics : shareholdingBasicsList){
                    shareholdingBasics.setId(null);
                    shareholdingBasics.setPropertyId(updateBasics.getId());
                }
                for (ShareholdingRecord shareholdingRecord : shareholdingRecordList){
                    shareholdingRecord.setId(null);
                    shareholdingRecord.setPropertyId(newRecord.getId());
                }
                shareholdingBasicsService.saveBatch(shareholdingBasicsList);
                shareholdingRecordService.saveBatch(shareholdingRecordList);
            }
        }else if ("2".equals(propertyChange.getNature())){
            //合伙人企业
            List<PartnerSituationChange> partnerSituationChangeList = partnerSituationChangeService.list(Wrappers.<PartnerSituationChange>lambdaQuery()
                    .eq(PartnerSituationChange::getPropertyId, propertyChange.getId()));
            partnerSituationBasicsService.removeByPropertyId(Collections.singletonList(updateBasics.getId()));
            if (CollectionUtil.isNotEmpty(partnerSituationChangeList)){
                List<PartnerSituationBasics> partnerSituationBasicsList = propertyChangeWrapper.situationChangeToBasics(partnerSituationChangeList);
                List<PartnerSituationRecord> partnerSituationRecordList = propertyChangeWrapper.situationChangeToRecord(partnerSituationChangeList);
                for (PartnerSituationBasics partnerSituationBasics : partnerSituationBasicsList){
                    partnerSituationBasics.setId(null);
                    partnerSituationBasics.setPropertyId(updateBasics.getId());
                }
                for (PartnerSituationRecord partnerSituationRecord : partnerSituationRecordList){
                    partnerSituationRecord.setId(null);
                    partnerSituationRecord.setPropertyId(newRecord.getId());
                }
                partnerSituationBasicsService.saveBatch(partnerSituationBasicsList);
                partnerSituationRecordService.saveBatch(partnerSituationRecordList);
            }

            List<PartnerOutboundChange> partnerOutboundChangeList = partnerOutboundChangeService.list(Wrappers.<PartnerOutboundChange>lambdaQuery()
                    .eq(PartnerOutboundChange::getPropertyId, propertyChange.getId()));
            partnerOutboundBasicsService.removeByPropertyId(Collections.singletonList(updateBasics.getId()));
            if (CollectionUtil.isNotEmpty(partnerOutboundChangeList)){
                List<PartnerOutboundBasics> partnerOutboundBasicsList = propertyChangeWrapper.outboundChangeToBasics(partnerOutboundChangeList);
                List<PartnerOutboundRecord> partnerOutboundRecordList = propertyChangeWrapper.outboundChangeToRecord(partnerOutboundChangeList);
                for (PartnerOutboundBasics partnerOutboundBasics : partnerOutboundBasicsList){
                    partnerOutboundBasics.setId(null);
                    partnerOutboundBasics.setPropertyId(updateBasics.getId());
                }
                for (PartnerOutboundRecord partnerOutboundRecord : partnerOutboundRecordList){
                    partnerOutboundRecord.setId(null);
                    partnerOutboundRecord.setPropertyId(newRecord.getId());
                }
                partnerOutboundBasicsService.saveBatch(partnerOutboundBasicsList);
                partnerOutboundRecordService.saveBatch(partnerOutboundRecordList);
            }
        }

        if (StringUtil.isNotBlank(propertyChange.getOrgCode())){
            //组织表名称更新
            Org org = orgService.getById(propertyChange.getOrgId());
            if (org != null && !org.getName().equals(propertyChange.getOrgName())){
                org.setName(propertyChange.getOrgName());
                orgService.updateById(org);
            }
        }
        List<String> ignoreChildPropertyIds = updateChildInfo(oldBasics, updateBasics, now);
        if (!oldBasics.getOrgName().equals(updateBasics.getOrgName())){
            //需要更新出资企业中的名称
            List<ContributorBasics> updateNameList = contributorBasicsService.list(Wrappers.<ContributorBasics>lambdaQuery()
                    .notIn(CollectionUtil.isNotEmpty(ignoreChildPropertyIds), ContributorBasics::getPropertyId, ignoreChildPropertyIds)
                    .and(andWrapper -> andWrapper
                            .eq(ContributorBasics::getOrgCode, updateBasics.getPropertyCode())
                            .or().eq(ContributorBasics::getContributor, oldBasics.getOrgName())));
            List<String> changePropertyIds = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(updateNameList)){
                for (ContributorBasics contributorBasics : updateNameList){
                    contributorBasics.setContributor(updateBasics.getOrgName());
                    changePropertyIds.add(contributorBasics.getPropertyId());
                }
                contributorBasicsService.updateBatchById(updateNameList);
            }
            List<PartnerSituationBasics> updateNamePSBList = partnerSituationBasicsService.list(Wrappers.<PartnerSituationBasics>lambdaQuery()
                    .notIn(CollectionUtil.isNotEmpty(ignoreChildPropertyIds), PartnerSituationBasics::getPropertyId, ignoreChildPropertyIds)
                    .and(andWrapper -> andWrapper
                            .eq(PartnerSituationBasics::getCode, updateBasics.getPropertyCode())
                            .or().eq(PartnerSituationBasics::getName, oldBasics.getOrgName())));
            if (CollectionUtil.isNotEmpty(updateNamePSBList)){
                for (PartnerSituationBasics partnerSituationBasics : updateNamePSBList){
                    partnerSituationBasics.setName(updateBasics.getOrgName());
                    changePropertyIds.add(partnerSituationBasics.getPropertyId());
                }
                partnerSituationBasicsService.updateBatchById(updateNamePSBList);
            }
            if (CollectionUtil.isNotEmpty(changePropertyIds)){
                List<PropertyBasics> propertyBasicsList = propertyBasicsService.listByIds(changePropertyIds);
                for (PropertyBasics propertyBasics : propertyBasicsList){
                    propertyBasics.setUpdateTime(now);
                }
                propertyBasicsService.updateBatchById(propertyBasicsList);
                List<PropertyRecord> propertyRecordList = propertyRecordService.getLatestByInitialIds(changePropertyIds);
                Map<String, PropertyRecord> newChildRecordMap = new HashMap<>();
                for (PropertyRecord changePropertyRecord : propertyRecordList){
                    String oldId = changePropertyRecord.getId();
                    changePropertyRecord.setId(null);
                    changePropertyRecord.setCreateTime(now);
                    changePropertyRecord.setUpdateTime(now);
                    propertyRecordService.save(changePropertyRecord);
                    copyFile(oldId, changePropertyRecord.getId());
                    newChildRecordMap.put(changePropertyRecord.getInitialId(), changePropertyRecord);
                }
                copyChildTableInfo(changePropertyIds, newChildRecordMap, null, null, null);
            }
        }
    }

    /**
     * 更新下级单位数据
     * @param oldBasics
     * @param updateBasics
     * @param now
     * @return
     */
    private List<String> updateChildInfo(PropertyBasics oldBasics, PropertyBasics updateBasics, Date now){
        int changeGradation = 0;
        String changeFundedName = "";
        String changeOrgName = "";
        String orgCode = updateBasics.getOrgCode();
        String oldOrgName = oldBasics.getOrgName();
        boolean flag = false;
        if (!oldBasics.getOrgGradation().equals(updateBasics.getOrgGradation())){
            //需要更新下级单位级次
            changeGradation = Integer.valueOf(updateBasics.getOrgGradation()) - Integer.valueOf(oldBasics.getOrgGradation());
            flag = true;
        }

        if (!oldBasics.getStateFundedName().equals(updateBasics.getStateFundedName())){
            //需要更新下级单位国家出资企业
            changeFundedName = updateBasics.getStateFundedName();
            flag = true;
        }

        if (!oldBasics.getOrgName().equals(updateBasics.getOrgName())){
            //需要更新出资企业中的名称 国家出资企业 所属集团全称
            changeOrgName = updateBasics.getOrgName();
            flag = true;
        }

        if (flag){
            List<PropertyBasics> childPropertyList = propertyBasicsService.list(Wrappers.<PropertyBasics>lambdaQuery()
                    .eq(PropertyBasics::getStatus, FormStatusConstant.FINISH)
                    .ne(PropertyBasics::getId, updateBasics.getId())
                    .likeRight(PropertyBasics::getPropertyCode, oldBasics.getPropertyCode()));
            if (CollectionUtil.isEmpty(childPropertyList)){
                return new ArrayList<>();
            }
            List<String> childPropertyBasicsIds = childPropertyList.stream().map(PropertyBasics::getId).collect(Collectors.toList());
            List<PropertyRecord> childPropertyRecordList = propertyRecordService.getLatestByInitialIds(childPropertyBasicsIds);
            Map<String, PropertyRecord> childInitialIdMap = childPropertyRecordList.stream().collect(Collectors.toMap(PropertyRecord::getInitialId, Function.identity()));
            Map<String, PropertyRecord> newChildRecordMap = new HashMap<>();
            for (PropertyBasics childProperty : childPropertyList){
                if (changeGradation != 0){
                    childProperty.setOrgGradation("00" + (Integer.valueOf(childProperty.getOrgGradation()) + changeGradation));
                }
                if (StringUtil.isNotBlank(changeFundedName)){
                    childProperty.setStateFundedName(changeFundedName);
                }
                if (oldOrgName.equals(childProperty.getAffiliatedOrgFullName())){
                    childProperty.setAffiliatedOrgFullName(changeOrgName);
                }
                childProperty.setUpdateTime(now);
                PropertyRecord newChildRecord = propertyBasicsWrapper.basicsToRecord(childProperty);
                newChildRecord.setCreateTime(now);
                newChildRecord.setUpdateTime(now);
                newChildRecord.setInitialId(childProperty.getId());
                if (StringUtil.isNotBlank(changeOrgName)){
                    if (oldOrgName.equals(newChildRecord.getAffiliatedOrgFullName())){
                        newChildRecord.setAffiliatedOrgFullName(changeOrgName);
                    }
                }
                propertyRecordService.save(newChildRecord);
                copyFile(childInitialIdMap.get(childProperty.getId()).getId(), newChildRecord.getId());
                newChildRecordMap.put(childProperty.getId(), newChildRecord);
            }
            copyChildTableInfo(childPropertyBasicsIds, newChildRecordMap, changeOrgName, oldOrgName, orgCode);
            propertyBasicsService.updateBatchById(childPropertyList);
            return  childPropertyBasicsIds;
        }
        return new ArrayList<>();
    }

    /**
     * 复制子表信息
     * @param childPropertyBasicsIds
     * @param newChildRecordMap
     * @param changeOrgName
     * @param orgCode
     */
    private void copyChildTableInfo(List<String> childPropertyBasicsIds, Map<String, PropertyRecord> newChildRecordMap, String changeOrgName, String oldOrgName, String orgCode){
        List<ContributorBasics> childContributorBasicsList = contributorBasicsService.list(Wrappers.<ContributorBasics>lambdaQuery()
                .in(ContributorBasics::getPropertyId, childPropertyBasicsIds));
        List<ShareholdingBasics> childShareholdingBasicsList = shareholdingBasicsService.list(Wrappers.<ShareholdingBasics>lambdaQuery()
                .in(ShareholdingBasics::getPropertyId, childPropertyBasicsIds));
        List<PartnerSituationBasics> childPartnerSituationBasicsList = partnerSituationBasicsService.list(Wrappers.<PartnerSituationBasics>lambdaQuery()
                .in(PartnerSituationBasics::getPropertyId, childPropertyBasicsIds));
        List<PartnerOutboundBasics> childPartnerOutboundBasicsList = partnerOutboundBasicsService.list(Wrappers.<PartnerOutboundBasics>lambdaQuery()
                .in(PartnerOutboundBasics::getPropertyId, childPropertyBasicsIds));
        if (CollectionUtil.isNotEmpty(childContributorBasicsList)){
            if (StringUtil.isNotBlank(changeOrgName)){
                List<ContributorBasics> updateChildList = new ArrayList<>();
                for (ContributorBasics contributorBasics : childContributorBasicsList){
                    if (orgCode.equals(contributorBasics.getOrgCode())
                            || oldOrgName.equals(contributorBasics.getContributor())){
                        contributorBasics.setContributor(changeOrgName);
                        updateChildList.add(contributorBasics);
                    }
                }
                if (CollectionUtil.isNotEmpty(updateChildList)){
                   contributorBasicsService.updateBatchById(updateChildList);
                }
            }
            List<ContributorRecord> recordList = propertyBasicsWrapper.contributorBasicsToRecord(childContributorBasicsList);
            for (ContributorRecord contributorRecord : recordList){
                contributorRecord.setId(null);
                contributorRecord.setPropertyId(newChildRecordMap.get(contributorRecord.getPropertyId()).getId());
            }
            contributorRecordService.saveBatch(recordList);
        }

        if (CollectionUtil.isNotEmpty(childShareholdingBasicsList)){
            List<ShareholdingRecord> recordList = propertyBasicsWrapper.shareholdingBasicsToRecord(childShareholdingBasicsList);
            for (ShareholdingRecord shareholdingRecord : recordList){
                shareholdingRecord.setId(null);
                shareholdingRecord.setPropertyId(newChildRecordMap.get(shareholdingRecord.getPropertyId()).getId());
            }
            shareholdingRecordService.saveBatch(recordList);
        }

        if (CollectionUtil.isNotEmpty(childPartnerSituationBasicsList)){
            if (StringUtil.isNotBlank(changeOrgName)){
                List<PartnerSituationBasics> updateChildList = new ArrayList<>();
                for (PartnerSituationBasics partnerSituationBasics : childPartnerSituationBasicsList){
                    if (orgCode.equals(partnerSituationBasics.getCode())
                            || oldOrgName.equals(partnerSituationBasics.getName())){
                        partnerSituationBasics.setName(changeOrgName);
                        updateChildList.add(partnerSituationBasics);
                    }
                }
                if (CollectionUtil.isNotEmpty(updateChildList)){
                    partnerSituationBasicsService.updateBatchById(updateChildList);
                }
            }
            List<PartnerSituationRecord> recordList = propertyBasicsWrapper.situationBasicsToRecord(childPartnerSituationBasicsList);
            for (PartnerSituationRecord partnerSituationRecord : recordList){
                partnerSituationRecord.setId(null);
                partnerSituationRecord.setPropertyId(newChildRecordMap.get(partnerSituationRecord.getPropertyId()).getId());
            }
            partnerSituationRecordService.saveBatch(recordList);
        }

        if (CollectionUtil.isNotEmpty(childPartnerOutboundBasicsList)){
            List<PartnerOutboundRecord> recordList = propertyBasicsWrapper.outboundBasicsToRecord(childPartnerOutboundBasicsList);
            for (PartnerOutboundRecord partnerOutboundRecord : recordList){
                partnerOutboundRecord.setId(null);
                partnerOutboundRecord.setPropertyId(newChildRecordMap.get(partnerOutboundRecord.getPropertyId()).getId());
            }
            partnerOutboundRecordService.saveBatch(recordList);
        }
    }

    private void copyFile(String oldRecordId, String newRecordId){
        try {
            List<PageData> fileList = fileDao.findParentId(oldRecordId);
            List<HashMap> recordFileList = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(fileList)){
                for (PageData file : fileList){
                    HashMap recordFile = new HashMap();
                    recordFile.putAll(file);
                    recordFile.put("id", UuidUtil.get32UUID());
                    recordFile.put("parentId", newRecordId);
                    recordFileList.add(recordFile);
                }
                fileDao.saveAll(recordFileList);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

//    private void saveAssociation(PropertyChange propertyChange,String recordId){ TODO DEL
//        try {
//            List<PageData> changeFiles=  fileDao.findParentId(propertyChange.getId());
//            String proId = propertyChange.getProId();
//            String orgId = propertyChange.getOrgId();
//            List<PageData> lastRecordFiles=  fileDao.findParentId(proId);
//            String oldFileName = "";
//            if (CollectionUtil.isNotEmpty(lastRecordFiles)){
//                Optional<PageData> recordFile = lastRecordFiles.stream().filter(m -> com.plian.Tools.StringUtil.isNotBlank(m.getString("type")) && "f5".equals(m.getString("type"))).findFirst();
//                if (recordFile.isPresent()) {
//                    PageData file = recordFile.get();
//                    oldFileName = file.getString("fileName");
//                }
//            }
//            if (CollectionUtil.isNotEmpty(changeFiles)){
//                Optional<PageData> changeFile = changeFiles.stream().filter(m -> com.plian.Tools.StringUtil.isNotBlank(m.getString("type")) && "f5".equals(m.getString("type"))).findFirst();
//                if (changeFile.isPresent()) {
//                    PageData file = changeFile.get();
//                    String fileName = file.getString("fileName");
//                    if (!fileName.contains(oldFileName)){
//                        EnterpriseAssociation enterpriseAssociation = new EnterpriseAssociation();
//                        enterpriseAssociation.setFillingYear(DateUtil.format(new Date(),DateUtil.PATTERN_YEAR));
//                        enterpriseAssociation.setFillingUnitId(orgId);
//                        enterpriseAssociation.setFillingTime(new Date());
//                        enterpriseAssociation.setFileName(fileName.substring(19));
//                        enterpriseAssociation.setBelongUnitId(orgId);
//                        enterpriseAssociation.setEffectTime(new Date());
//                        enterpriseAssociation.setFileStatus(1);
//                        enterpriseAssociation.setAssociationStatus(1);
//                        enterpriseAssociation.setProId(recordId);
//                        enterpriseAssociation.setOrgId(orgId);
//                        HashMap fileMap = new HashMap(file);
//                        fileMap.remove("id");
//                        fileMap.remove("parentId");
//                        fileMap.put("itFileName",fileMap.get("fileName"));
//                        enterpriseAssociation.setDocList(Collections.singletonList(fileMap));
//                        //查询老的
//                        List<EnterpriseAssociation> oldAssociations = changeAssociationService.list(new LambdaQueryWrapper<EnterpriseAssociation>().eq(EnterpriseAssociation::getProId, proId));
//                        if (CollectionUtil.isNotEmpty(oldAssociations)){
//                            EnterpriseAssociation oldAssociation = oldAssociations.get(0);
//                            if (Optional.ofNullable(oldAssociation.getInitialId()).isPresent()){
//                                enterpriseAssociation.setInitialId(oldAssociation.getInitialId());
//                            }else {
//                                enterpriseAssociation.setInitialId(oldAssociation.getInitialId());
//                            }
//                            enterpriseAssociation.setVersion(oldAssociation.getVersion());
//                            enterpriseAssociation.setLastVersionId(oldAssociation.getId());
//                        }
//                        changeAssociationService.submit(enterpriseAssociation);
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
}
